var username = window.sessionStorage.getItem("username");
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    //添加验证规则
    form.verify({
        newPwd : function(value, item){
            if(value.length < 6){
                return "密码长度不能小于6位";
            }
        },
        confirmPwd : function(value, item){
            if(!new RegExp($("#newPassword").val()).test(value)){
                return "两次输入密码不一致，请重新输入！";
            }
        }
    });

    form.on("submit(changePwd)", function (data) {
        $.ajax({
            "url": "/admin/sys/user/updatePassword.do",
            "type": "GET",
            "dataType": "json",
            "data": {username: $("#username").val(),
                oldPassword:$("#oldPassword").val(),
                newPassword:$("#newPassword").val()
            },
            "success": function (ret) {
                if (ret.code == 0) {
                    window.location.href = getRootPath_web() + "/html/admin/login.html";
                } else {
                    layer.alert(ret.msg);
                }
            }
        });
        return false;
    });

    $(document).ready(function () {
        $('#username').val(username);
    });
});